package club.itstudio.itouc.core.annotation

import club.itstudio.itouc.config.ElectiveCoursecConfig
import club.itstudio.itouc.core.util.ResultUtil
import club.itstudio.itouc.service.JwOps
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.springframework.stereotype.Component

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class ElectiveConf


@Aspect
@Component
class ElectiveConfHandler(val ecConfig: ElectiveCoursecConfig,
                      val jwOps: JwOps) {
    @Around("@annotation(club.itstudio.itouc.core.annotation.ElectiveConf)")
    fun access(joinPoint: ProceedingJoinPoint): Any {
        if (!ecConfig.open) return ResultUtil.error("选课系统未开放")
        return joinPoint.proceed()
    }
}

